﻿using System;
using System.Globalization;
using System.Windows;
using System.Windows.Data;

namespace Red.Controls.Converters
{
    public sealed class BoolVisibilityConverter : IValueConverter
    {
        #region IValueConverter implementation

        // http://stackoverflow.com/questions/3128023/wpf-booleantovisibilityconverter-that-converts-to-hidden-instead-of-collapsed-wh
        public object Convert( object value, Type targetType, object parameter, CultureInfo culture )
        {
            bool flag = false;
            if ( value is bool )
            {
                flag = (bool)value;
            }
            else if ( value is bool? )
            {
                bool? nullable = (bool?)value;
                flag = nullable.HasValue ? nullable.Value : false;
            }
            return ( flag ? Visibility.Visible : Visibility.Hidden );
        }

        public object ConvertBack( object value, Type targetType, object parameter, CultureInfo culture )
        {
            throw new NotImplementedException();
        }

        #endregion IValueConverter implementation
    }
}
